<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Estado</title>
         <ui:include src="/WEB-INF/partials/layout/admin/includes.xhtml"/>
    </h:head>
    <h:body>
         <ui:include src="/WEB-INF/partials/layout/admin/menu.xhtml"/>
        
         <h:form prependId="false">
                <p:dialog modal="true" widgetVar="removeVar" id="remove" header="Confirmar Remoção?">
                <p:panel id="panelRemove">
                    <p:panelGrid columns="2"  style="width:100%">
                        <h:outputLabel value="Estado " for="estado" />
                        <h:outputText id="pais" value="#{EstadoCrudMB.entity.nome}"/>
                        <h:outputLabel value="Sigla" for="sigla" />
                        <h:outputText id="sigla" value="#{EstadoCrudMB.entity.sigla}"/>
                        <h:outputLabel value="Pais" for="pais"/>
                        <ui:repeat value="#{EstadoCrudMB.entity.pais}" var="pais">
                            <h:outputText id="pais" value="#{pais.nome}" title="Pais" />
                        </ui:repeat>
                    </p:panelGrid>

                    <f:facet name="footer">
                        <p:commandButton value="Cancelar" oncomplete="removeVar.hide()" process="@this"/>
                        <p:commandButton value="Confirmar" oncomplete="removeVar.hide()"  update="lista" 
                                         action="#{EstadoCrudMB.delete()}" process="panelRemove">
                            <f:param value="#{EstadoCrudMB.entity.id}" />
                        </p:commandButton>
                    </f:facet>
                </p:panel>
            </p:dialog>
            
            <p:messages autoUpdate="true" />
            <h1><h:outputText value="Listagem de Estados"/></h1>
           
            <p:dataTable value="#{EstadoCrudMB.estados}" var="item" id="lista" rows="20">
                    <f:facet name="header">
                        <p:commandButton value="Cadastrar Estado" action="#{EstadoCrudMB.newEntity}"
                                         oncomplete="window.location = './form.xhtml'" />
                    </f:facet>
                    <p:column style="width: 20%">
                        <p:commandButton value="Editar" onclick="window.location='./form.xhtml?id=#{item.id}'"/>
                        <p:commandButton value="Excluir" update="panelRemove" action="#{EstadoCrudMB.setEntity(item)}"
                                         oncomplete="removeVar.show()" />
                        <f:param name="id" value="#{item.id}" />
                    </p:column>
                    <p:column style="width: 10%">
                        <f:facet name="header">
                            <h:outputText value="Id"/>
                        </f:facet>
                        <h:outputText value="#{item.id}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Nome"/>
                        </f:facet>
                        <h:outputText value="#{item.nome}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Sigla"/>
                        </f:facet>
                        <h:outputText value="#{item.sigla}"/>
                    </p:column>
                    <p:column style="width: 20%">
                        <f:facet name="header">
                            <h:outputText value="Pais"/>
                        </f:facet>
                        <ui:repeat value="#{item.pais}" var="pais" >
                            <h:outputText value="#{pais.nome}"/>
                        </ui:repeat>
                    </p:column>
                </p:dataTable>
                
            
        </h:form>
    </h:body>
</html>
